Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(idempotency): manipulate idempotent response via response hook #3071

Merged

Conversation

arnabrahman
Copy link
Contributor

Summary

According to the issue description, when idempotency is triggered we should be able to call a function. This function will allow users to modify the response if necessary. This PR adds this functionality via a response hook.

Changes

  • Implement a user-provided function that is triggered during idempotency.
  • Introduce a new configuration option responseHook in the IdempotencyConfig class.
  • Modify the determineResultFromIdempotencyRecord function to be non-static, allowing it to access the configuration.
  • Inside the determineResultFromIdempotencyRecord function, check for the presence of responseHook during an idempotent request, and trigger it if it exists.
  • Add test cases for responseHook in the unit tests for the determineResultFromIdempotencyRecord function.
  • Update the documentation for responseHook following the Python Powertools documentation as a reference.

Issue number: #2887


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@arnabrahman arnabrahman requested review from a team as code owners September 15, 2024 10:57
@boring-cyborg boring-cyborg bot added documentation Improvements or additions to documentation idempotency This item relates to the Idempotency Utility tests PRs that add or change tests labels Sep 15, 2024
@pull-request-size pull-request-size bot added the size/L PRs between 100-499 LOC label Sep 15, 2024
@arnabrahman
Copy link
Contributor Author

I don't know why but when i ran docs-website-build-run it gave me this error.

raceback (most recent call last):
  File "/usr/local/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/mkdocs/__main__.py", line 268, in serve_command
    serve.serve(**kwargs)
  File "/usr/local/lib/python3.11/site-packages/mkdocs/commands/serve.py", line 54, in serve
    config = get_config()
             ^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/mkdocs/commands/serve.py", line 43, in get_config
    config = load_config(
             ^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/mkdocs/config/base.py", line 374, in load_config
    errors, warnings = cfg.validate()
                       ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/mkdocs/config/base.py", line 231, in validate
    run_failed, run_warnings = self._validate()
                               ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/mkdocs/config/base.py", line 188, in _validate
    self[key] = config_option.validate(value)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/mkdocs/config/base.py", line 55, in validate
    return self.run_validation(value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/mkdocs/config/config_options.py", line 868, in run_validation
    return theme.Theme(**theme_config)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/mkdocs/theme.py", line 61, in __init__
    self._load_theme_config(name)
  File "/usr/local/lib/python3.11/site-packages/mkdocs/theme.py", line 126, in _load_theme_config
    theme_dir = utils.get_theme_dir(name)
                ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/mkdocs/utils/__init__.py", line 259, in get_theme_dir
    return os.path.dirname(os.path.abspath(theme.load().__file__))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen posixpath>", line 399, in abspath
TypeError: expected str, bytes or os.PathLike object, not NoneType

I had to revert to mkdocs-material==9.5.33, basically this to make it work.

@github-actions github-actions bot added the feature PRs that introduce new features or minor changes label Sep 15, 2024
@dreamorosi
Copy link
Contributor

I don't know why but when i ran docs-website-build-run it gave me this error.

Thank you for reporting this! I've tried to take a quick look and I can't seem to figure out why this is happening, the error message is also quite unhelpful.

The only thing I was able to figure out is that this seem to happen only when using the docker image. If I run the docs using Python locally (commands below) it builds and works normally, so I am not sure.

Create a virtual environment & enable it (optional but recommended):

python3 -m venv .venv
source .venv/bin/activate

Then install the dependencies & start the local server:

pip install --require-hashes -r docs/requirements.txt
mkdocs serve --dev-addr=0.0.0.0:8080

I had to revert to mkdocs-material==9.5.33, basically this to make it work.

This seems the easiest way to unblock you, unless you already have Python 3.x on your machine and want to run the commands above.

For now I won't revert the commit since this seems to affect only the dev environment, but not the regular deployments. I'll however continue to look into it. I have opened an issue to track this #3073.


We'll try to review the PR between later today & tomorrow morning. For the better part of today we'll focus on releasing v2.8.0.

Copy link
Contributor

@dreamorosi dreamorosi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great quality PR, @arnabrahman! No notes 💯

Thank you also for the patience in me reviewing it, appreciate your contributions always!

Mid next week at the latest I'll work on adding more issues for potential contributions, stay tuned in case you're interested :) In the meantime, there's also this one that might interest you.

@dreamorosi dreamorosi linked an issue Sep 19, 2024 that may be closed by this pull request
2 tasks
Copy link

@dreamorosi dreamorosi merged commit f7c1769 into aws-powertools:main Sep 19, 2024
15 checks passed
@arnabrahman arnabrahman deleted the 2887-idempotency-trigger-hook branch September 20, 2024 04:06
@arnabrahman
Copy link
Contributor Author

Actually, i have faced the issue at my work. Made a comment there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation feature PRs that introduce new features or minor changes idempotency This item relates to the Idempotency Utility size/L PRs between 100-499 LOC tests PRs that add or change tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: manipulating the idempotent response
3 participants